#pragma once

#include <iostream>
#include <string>
#include <sys/types.h>
#include <sys/socket.h>
#include <cstring>

namespace ns_protocol
{
    #define MYSELF 1
    #define SPACE " "
    #define SPACE_LEN strlen(SPACE)

    class Request
    {
    public:
        // 1. 自主实现
        // 2. 使用线程的方案
        std::string Serialize()
        {
        #ifdef MYSELF 
            std::string str;
            str = std::to_string(x_);
            str += SPACE;
            str += op_;
            str += SPACE;
            str += std::to_string(y_);
            return str;
        #else
            std::cout << "TODO" << std::endl;
        #endif
        }
        bool Deserialized(const std::string& str)
        {
        #ifdef MYSELF 
            std::size_t pos = str.find(SPACE);
            
        #else
            std::cout << "TODO" << std::endl;
        #endif
        }
    public:
        Request()
        {}
        Request(int x, int y, char op)
            :x_(x)
            ,y_(y)
            ,op_(op)
        {}
        ~Request(){}
    public:
        int x_;
        int y_;
        char op_;
    };
    class Response
    {
    public:
        std::string Serialize()
        {

        }
        bool Deserialized(const std::string& package)
        {

        }
    public:
        Response()
        {}
        Response(int result, int code)
            :result_(result)
            ,code_(code)
        {}
        ~Response(){}
    public:
        int result_; // 计算结果
        int code_; // 计算结果的状态码
    };

    std::string Recv(int sock)
    {
        char inbuffer[1024];
        ssize_t s = recv(sock, inbuffer, sizeof(inbuffer), 0);
        if (s > 0)
        {
            return inbuffer;
        }
    }

    void Send(int sock, const std::string str)
    {
        send(sock, str.c_str(), str.size(), 0);
    }
}